home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 April / Software of the Month Club 1996 April.iso / pc / os2 / psutils / src / getafm < prev    next >
Text File  |  1996-02-21  |  6KB  |  359 lines

  1. #!/bin/sh
  2.  
  3. if [ $# -ne 1 ]; then
  4.   echo "usage: $0 font-name | gsnd - >font-name.afm" >&2
  5.   exit 1
  6. fi
  7.  
  8. cat << EOF
  9. %!
  10. % produce .afm for $1
  11. % (c) 1993 by Robert Joop <rj@rainbow.in-berlin.de>
  12. % inspired by two other versions of this theme which are
  13. %    getafm 1.00 (c) AJCD
  14. % and getafm.ps by an unknown author,
  15. %    modified by J. Daniel Smith <dsmith@mailhost.aa.cad.slb.com>
  16.  
  17. % Metrics dictionary code added by AJCD, 7/6/93
  18.  
  19. /getafmdict 100 dict dup begin
  20.  
  21.   /buf 256 string def
  22.   /buf2 16 string def
  23.  
  24.   /prany    % dict dictname printname -> dict
  25.   {
  26.     2 index 2 index cvn known
  27.     {
  28.       print % printname
  29.       ( ) print
  30.       1 index exch cvn get =
  31.     }
  32.     {
  33.       (Comment /FontInfo contains no /) print
  34.       2 copy eq
  35.       {
  36.         = % printname
  37.     pop % dictname
  38.       }
  39.       {
  40.     exch
  41.     print % dictname
  42.     (, therefore no ) print
  43.     = % printname
  44.       }
  45.       ifelse
  46.     }
  47.     ifelse
  48.   }
  49.   bind def
  50.  
  51.   /printfontname
  52.   {
  53.     (FontName)dup prany
  54.   }
  55.   bind def
  56.  
  57.   /printfontinfo
  58.   {
  59.     dup /FontInfo known
  60.     {
  61.       dup /FontInfo get
  62.     (FullName)dup prany
  63.     (FamilyName)dup prany
  64.     (Weight)dup prany
  65.     (ItalicAngle)dup prany
  66.     (isFixedPitch)(IsFixedPitch) prany
  67.     (UnderlinePosition)dup prany
  68.     (UnderlineThickness)dup prany
  69.     (Version)(version) prany
  70.     (Notice)dup prany
  71.       pop
  72.     }
  73.     {
  74.       (Comment Font lacks a /FontInfo!)=
  75.     }
  76.     ifelse
  77.   }
  78.   bind def
  79.  
  80.   /prbbox % llx lly urx ury -> -
  81.   {
  82.     4 1 roll 3 1 roll exch % swap top 4 elements
  83.     4 { ( ) print buf cvs print } repeat
  84.   }
  85.   bind def
  86.  
  87.   /getbbox % fontdict chardict character -> fontdict chardict llx lly urx ury
  88.   {
  89.     gsave
  90.       2 index setfont 0 0 moveto
  91.       false charpath flattenpath pathbbox
  92.     grestore
  93.   }
  94.   bind def
  95.  
  96.   /printmiscinfo
  97.   {
  98.     dup /FontBBox known
  99.     {
  100.       (FontBBox) print
  101.       dup /FontBBox get aload pop prbbox ()=
  102.     }
  103.     {
  104.       (Comment missing required /FontBBox)=
  105.       quit
  106.     }
  107.     ifelse
  108.     2 copy exch get
  109.       dup /H known
  110.       1 index /x known and
  111.       1 index /d known and
  112.       1 index /p known and
  113.       dup /looksRoman exch def
  114.       {
  115.     (CapHeight ) print
  116.     (H) getbbox
  117.     ceiling cvi = pop pop pop
  118.     (XHeight ) print
  119.     (x) getbbox
  120.     ceiling cvi = pop pop pop
  121.     (Ascender ) print
  122.     (d) getbbox
  123.     ceiling cvi = pop pop pop
  124.     (Descender ) print
  125.     (p) getbbox
  126.     pop pop floor cvi = pop
  127.       }
  128.       {
  129.     (Comment font doesn't contain H, x, d and p; therefore no CapHeight, XHeight, Ascender and Descender)=
  130.       }
  131.       ifelse
  132.     pop
  133.     dup /Encoding get
  134.       [
  135.     [ (ISOLatin1Encoding) /ISOLatin1Encoding ]
  136.     [ (AdobeStandardEncoding) /StandardEncoding ]
  137.       ]
  138.       {
  139.     aload pop dup where
  140.     {
  141.       exch get 2 index eq
  142.       {
  143.         (EncodingScheme ) print
  144.         buf cvs =
  145.       }
  146.       {
  147.         pop
  148.       }
  149.       ifelse
  150.     }
  151.     {
  152.       pop pop
  153.     }
  154.     ifelse
  155.       }
  156.       forall
  157.     pop
  158.   }
  159.   bind def
  160.  
  161.   /printcharmetric
  162.   {
  163.     % chardictname fontdict charnamedict encoding charindex charname
  164.  
  165.     4 index dup length dict dup begin exch
  166.       {
  167.     1 index /FID ne
  168.     2 index /UniqueID ne
  169.     and
  170.     {
  171.       1 index /Encoding eq { 256 array copy } if
  172.       def
  173.     }
  174.     { pop pop }
  175.     ifelse
  176.       }
  177.       forall
  178.     end
  179.     dup /Encoding get 32 3 index put
  180.     /f2 exch definefont
  181.     setfont
  182.  
  183.     (C ) print
  184.     1 index buf cvs print
  185.  
  186.     ( ; WX ) print
  187. % Metrics entries are:
  188. %       1 number:               which is the character width
  189. %       an array of 2 numbers:  which are the left sidebearing and width
  190. %       an array of 4 numbers:  x & y left sidebearing, width and height
  191.     dup 5 index         % /charname fontdict
  192.     dup /Metrics known {
  193.        /Metrics get exch 2 copy known {
  194.           get dup type /arraytype eq {
  195.              dup length 2 eq
  196.              {1 get} {2 get} ifelse
  197.           } if
  198.           round cvi buf cvs print
  199.        } {
  200.           pop pop ( ) stringwidth pop round cvi buf cvs print
  201.        } ifelse
  202.     } {
  203.        pop pop ( ) stringwidth pop round cvi buf cvs print
  204.     } ifelse
  205.  
  206.     ( ; N ) print
  207.     dup buf cvs print
  208.  
  209.     ( ; B) print
  210.     gsave
  211.       newpath 0 0 moveto
  212.       ( ) true charpath flattenpath pathbbox
  213.     grestore
  214.     2 { ceiling cvi 4 1 roll } repeat
  215.     2 { floor cvi 4 1 roll } repeat
  216.     prbbox
  217.  
  218.     looksRoman
  219.     {
  220.       [
  221.     [ /f [ /i /f /l ] ]
  222.     [ /ff [ /i /l ] ]
  223.       ]
  224.       {
  225.     aload pop 1 index 3 index eq
  226.     {
  227.       { 
  228.         1 index buf cvs
  229.         length
  230.         1 index buf2 cvs dup length
  231.         2 index add
  232.         buf
  233.         4 2 roll putinterval
  234.         buf 0
  235.         3 -1 roll getinterval
  236.         dup cvn
  237.         7 index
  238.         exch known
  239.         {
  240.           exch
  241.           ( ; L ) print
  242.           buf2 cvs print
  243.           ( ) print
  244.           print
  245.         }
  246.         {
  247.           pop pop
  248.         }
  249.         ifelse
  250.       }
  251.       forall
  252.       pop 
  253.     }
  254.     {
  255.       pop pop
  256.     }
  257.     ifelse
  258.       }
  259.       forall
  260.     }
  261.     if
  262.     pop
  263.  
  264.     ( ;)=
  265.   }
  266.   bind def
  267.  
  268.   /printcharmetrics
  269.   {
  270.     (StartCharMetrics ) print
  271.     2 copy exch get length 1 sub buf cvs =
  272.  
  273.     256 dict dup begin
  274.       1 index /Encoding get
  275.       { null def }
  276.       forall
  277.     end
  278.     % chardictname fontdict charnamedict
  279.     1 index /Encoding get
  280.     0 1 255
  281.     {
  282.       % encoding index
  283.       2 copy get
  284.       dup /.notdef eq { pop } { printcharmetric } ifelse
  285.       pop % index
  286.     } for
  287.  
  288.     -1
  289.     3 index 5 index get
  290.     {
  291.       pop
  292.       dup /.notdef eq
  293.       { pop }
  294.       {
  295.     % chardictname fontdict charnamedict encoding charindex charname
  296.     dup 4 index exch known
  297.     { pop }
  298.     { printcharmetric }
  299.     ifelse
  300.       }
  301.       ifelse
  302.     }
  303.     forall
  304.     % charnamedict encoding index
  305.     pop pop pop
  306.  
  307.     (EndCharMetrics)=
  308.   }
  309.   bind def
  310.  
  311.   /printfontmetrics
  312.   {
  313.     (StartFontMetrics 3.0)=
  314.     (Comment Produced by getafm 3.0 (which is by rj@rainbow.in-berlin.de))=
  315.  
  316.     printfontname
  317.     printfontinfo
  318.     printmiscinfo
  319.     printcharmetrics
  320.  
  321.     (EndFontMetrics)=
  322.   }
  323.   bind def
  324.  
  325. end def
  326.  
  327. /getafm
  328. {
  329.   getafmdict begin
  330.     save exch
  331.       findfont 1000 scalefont 
  332.  
  333.       null
  334.       [ /CharDefs /CharData /CharProcs /CharStrings ]
  335.       {
  336.     2 index 1 index known { exch } if
  337.     pop
  338.       }
  339.       forall
  340.       dup null eq
  341.       {
  342.     (can't find dictionary with character data!)=
  343.     quit
  344.       }
  345.       if
  346.       exch % dictname fontdict
  347.  
  348.       printfontmetrics
  349.  
  350.       pop pop
  351.     restore
  352.   end
  353. }
  354. bind def
  355.  
  356. /$1 getafm
  357.  
  358. EOF
  359.